//
//  LCAppAgentViewController.m
//  lechuang
//
//  Created by Mr_hi on 2023/3/29.
//  Copyright © 2023 Mooyi. All rights reserved.
//

#import "LCAppAgentViewController.h"
#import "LCUserModel.h"

#import "LCTaskService.h"

@interface LCAppAgentViewController ()

@property (weak, nonatomic)NSString *businessid;

@property (weak, nonatomic) IBOutlet UILabel *typeLb;

@property (weak, nonatomic) IBOutlet UITextField *nameTfl;

@property (weak, nonatomic) IBOutlet UITextField *phoneTfl;

@property (weak, nonatomic) IBOutlet UITextField *areaTfl;

@end

@implementation LCAppAgentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if (LCUserDefGet(UserInfo)) {
        LCUserModel * userData = [LCUserModel mj_objectWithKeyValues:LCUserDefGet(UserInfo)];
        self.businessid = userData.businessid;
    }
}

- (IBAction)backClick:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)typeBtnAction:(UIButton *)sender {
    NSMutableArray * actionArr = [NSMutableArray array];
    if ([self.businessid isEqualToString:@"0"]) {
        [actionArr addObject:@"成为一级代理"];
    } else if ([self.businessid isEqualToString:@"1"]) {
        [actionArr addObject:@"成为二级代理"];
    }
    [actionArr addObject:@"我要开发APP"];
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    
    for (NSString * actionStr in actionArr) {
        UIAlertAction *action = [UIAlertAction actionWithTitle:actionStr style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            self.typeLb.text = action.title;
            self.typeLb.textColor = [UIColor colorWithHexString:@"#222222"];
        }];
        [alert addAction:action];
    }
    [alert addAction:cancel];
    [self presentViewController:alert animated:YES completion:nil];
}

- (IBAction)submitBtnAction:(UIButton *)sender {
    if ([self.typeLb.text isEqualToString:@"请选择申请类目"]) {
        [self showErrorText:@"请选择申请类目"];
        return;
    }
    if (!self.nameTfl.text.length) {
        [self showErrorText:self.nameTfl.placeholder];
        return;
    }
    if (!self.phoneTfl.text.length) {
        [self showErrorText:self.phoneTfl.placeholder];
        return;
    }
    if (![NSString isMobileNumber:self.phoneTfl.text]) {
        [self showErrorText:@"请输入正确的手机号"];
        return;
    }
    if (!self.areaTfl.text.length) {
        [self showErrorText:self.areaTfl.placeholder];
        return;
    }

    NSMutableDictionary * other = [NSMutableDictionary dictionary];
    other[@"type"] = self.typeLb.text;
    other[@"surname"] = self.nameTfl.text;
    other[@"phone"] = self.phoneTfl.text;
    other[@"area"] = self.areaTfl.text;

    [LCTaskService saveFormWithFormId:@"10000001" Other:other Block:^(BOOL isSuccess) {
        if (isSuccess) {
            [self showSuccessText:@"申请成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }
    }];
}


@end
